package com.niit.bigdata.service;

import com.niit.bigdata.util.RedisUtil;
import org.springframework.stereotype.Service;

@Service
public class RedisService {
    private RedisUtil redisUtil;

    RedisService(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }

    public void set(String key, Object value) {
        redisUtil.set(key, value);
    }

    public void setWithExpiration(String key, Object value, long expirationSeconds) {
        redisUtil.setWithExpiration(key, value, expirationSeconds);
    }

    public Object get(String key) {
        return redisUtil.get(key);
    }

    public String getString(String key) {
        return redisUtil.getString(key);
    }

    public void delete(String key) {
        redisUtil.delete(key);
    }

    public void updateTotal() {
        if (redisUtil.get("total") == null) {
            redisUtil.set("total", 0);
        }
        int total = (int) redisUtil.get("total");

        redisUtil.set("total", total + 1);
    }
}
